﻿using ConfigServices;
using ConfigServices.LayeredConfig;
using LogServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MailServices
{
    /// <summary>
    /// 这里是为了演示DI的能力,如果真的要实现发邮件可以使用开源库:MailKit
    /// </summary>
    public class MailService : IMailService
    {
        private readonly ILogProvider log;
        //private readonly IConfigService config;

        private readonly IConfigReader config;

        public MailService(ILogProvider log, IConfigReader config)
        {
            this.log = log;
            this.config = config;
        }

        public void send(string title, string to, string body)
        {
            log.LogInfo("准备发送邮件!");
            string smtpServer=config.GetValue("SmtpServer");//读取配置:邮件服务器地址
            string userName = config.GetValue("UserName");//读取配置:邮件用户名
            string password = config.GetValue("Password");//读取配置:邮件密码
            Console.WriteLine($"邮件服务器地址:{smtpServer},{userName},{password}");
            Console.WriteLine($"真发邮件啦{title},{to}");
            log.LogInfo("邮件发送完成!");
          
        }
    }
}
